home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / c_lines.zip / C_LINES.C next >
C/C++ Source or Header  |  1992-01-28  |  34KB  |  1,244 lines

  1. /* A lexical scanner generated by flex */
  2.  
  3. /* scanner skeleton version:
  4.  * $Header: /usr/fsys/odin/a/vern/flex/RCS/flex.skel,v 2.16 90/08/03 14:09:36 vern Exp $
  5.  */
  6.  
  7. #define FLEX_SCANNER
  8.  
  9. #include <stdio.h>
  10.  
  11.  
  12. /* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */
  13. #ifdef c_plusplus
  14. #ifndef __cplusplus
  15. #define __cplusplus
  16. #endif
  17. #endif
  18.  
  19.  
  20. #ifdef __cplusplus
  21.  
  22. #include <stdlib.h>
  23. #include <osfcn.h>
  24.  
  25. /* use prototypes in function declarations */
  26. #define YY_USE_PROTOS
  27.  
  28. /* the "const" storage-class-modifier is valid */
  29. #define YY_USE_CONST
  30.  
  31. #else    /* ! __cplusplus */
  32.  
  33. #ifdef __STDC__
  34.  
  35. #ifdef __GNUC__
  36. #include <stddef.h>
  37. void *malloc( size_t );
  38. void free( void* );
  39. #else
  40. #include <stdlib.h>
  41. #endif    /* __GNUC__ */
  42.  
  43. #define YY_USE_PROTOS
  44. #define YY_USE_CONST
  45.  
  46. #endif    /* __STDC__ */
  47. #endif    /* ! __cplusplus */
  48.  
  49.  
  50. #if defined(__TURBOC__) || defined(MSDOS)
  51. #include <stdlib.h>
  52. #include <io.h>
  53. #define YY_USE_CONST
  54. #define YY_USE_PROTOS
  55. #endif
  56.  
  57. #ifndef YY_USE_CONST
  58. #define const
  59. #endif
  60.  
  61. #ifdef YY_USE_PROTOS
  62. #define YY_PROTO(proto) proto
  63. #else
  64. #define YY_PROTO(proto) ()
  65. /* we can't get here if it's an ANSI C compiler, or a C++ compiler,
  66.  * so it's got to be a K&R compiler, and therefore there's no standard
  67.  * place from which to include these definitions
  68.  */
  69. char *malloc();
  70. int free();
  71. int read();
  72. #endif
  73.  
  74.  
  75. /* amount of stuff to slurp up with each read */
  76. #ifndef YY_READ_BUF_SIZE
  77. #define YY_READ_BUF_SIZE 8192
  78. #endif
  79.  
  80. /* returned upon end-of-file */
  81. #define YY_END_TOK 0
  82.  
  83. /* copy whatever the last rule matched to the standard output */
  84.  
  85. /* cast to (char *) is because for 8-bit chars, yytext is (unsigned char *) */
  86. /* this used to be an fputs(), but since the string might contain NUL's,
  87.  * we now use fwrite()
  88.  */
  89. #define ECHO (void) fwrite( (char *) yytext, yyleng, 1, yyout )
  90.  
  91. /* gets input and stuffs it into "buf".  number of characters read, or YY_NULL,
  92.  * is returned in "result".
  93.  */
  94. #define YY_INPUT(buf,result,max_size) \
  95.     if ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \
  96.         YY_FATAL_ERROR( "read() in flex scanner failed" );\
  97.     else yy_strip_high_bits(buf,result);
  98. #define YY_NULL 0
  99.  
  100. /* no semi-colon after return; correct usage is to write "yyterminate();" -
  101.  * we don't want an extra ';' after the "return" because that will cause
  102.  * some compilers to complain about unreachable statements.
  103.  */
  104. #define yyterminate() return ( YY_NULL )
  105.  
  106. /* report a fatal error */
  107.  
  108. /* The funky do-while is used to turn this macro definition into
  109.  * a single C statement (which needs a semi-colon terminator).
  110.  * This avoids problems with code like:
  111.  *
  112.  *     if ( something_happens )
  113.  *        YY_FATAL_ERROR( "oops, the something happened" );
  114.  *    else
  115.  *        everything_okay();
  116.  *
  117.  * Prior to using the do-while the compiler would get upset at the
  118.  * "else" because it interpreted the "if" statement as being all
  119.  * done when it reached the ';' after the YY_FATAL_ERROR() call.
  120.  */
  121.  
  122. #define YY_FATAL_ERROR(msg) \
  123.     do \
  124.         { \
  125.         (void) fputs( msg, stderr ); \
  126.         (void) putc( '\n', stderr ); \
  127.         exit( 1 ); \
  128.         } \
  129.     while ( 0 )
  130.  
  131. /* default yywrap function - always treat EOF as an EOF */
  132. #define yywrap() 1
  133.  
  134. /* enter a start condition.  This macro really ought to take a parameter,
  135.  * but we do it the disgusting crufty way forced on us by the ()-less
  136.  * definition of BEGIN
  137.  */
  138. #define BEGIN yy_start = 1 + 2 *
  139.  
  140. /* action number for EOF rule of a given start state */
  141. #define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
  142.  
  143. /* special action meaning "start processing a new file" */
  144. #define YY_NEW_FILE \
  145.     do \
  146.         { \
  147.         yy_init_buffer( yy_current_buffer, yyin ); \
  148.         yy_load_buffer_state(); \
  149.         } \
  150.     while ( 0 )
  151.  
  152. /* default declaration of generated scanner - a define so the user can
  153.  * easily add parameters
  154.  */
  155. #define YY_DECL int yylex YY_PROTO(( void )) 
  156.  
  157. /* code executed at the end of each rule */
  158. #define YY_BREAK break;
  159.  
  160. #define YY_END_OF_BUFFER_CHAR 0
  161.  
  162. #ifndef YY_BUF_SIZE
  163. #define YY_BUF_SIZE (YY_READ_BUF_SIZE * 2) /* size of default input buffer */
  164. #endif
  165.  
  166. typedef struct yy_buffer_state *YY_BUFFER_STATE;
  167.  
  168. #define YY_CHAR char
  169. # line 1 "c_lines.l"
  170. #define INITIAL 0
  171. # line 2 "c_lines.l"
  172.     #include <string.h>
  173.  
  174.     /* These are counts on a per-file basis. (ie. number of whatever's in  */
  175.     /* the current file.  */
  176.  
  177.     unsigned nl=0;               /* lines                                */
  178.     unsigned ppd=0;              /* pre-processor directives             */
  179.     unsigned comments=0;         /* comments ( of course )               */
  180.     unsigned comment_lines=0;    /* lines occupied by comments           */
  181.     unsigned fl_cpp=0;           /* lines occupied only by c++ comments  */
  182.     unsigned skipped=0;          /* lines skipped due to #if 0 directives*/
  183.     unsigned files=0;            /* files we've looked at                */
  184.  
  185.     unsigned nested=0;           /* nesting level of pre-processor lines */
  186.  
  187.     /* this is a list of extensions to search for if none is given      */
  188.     /* if you modify it, be sure to keep a NULL as the last entry       */
  189.     char *extensions[] = {
  190.         ".C",".CPP",".CXX",".H",".HPP",".HXX",".CC",NULL
  191.     };
  192.  
  193.     unsigned matched=0;
  194.  
  195. #define SKIP 1
  196. #define COMMENT 2
  197. # line 30 "c_lines.l"
  198.  
  199. /* done after the current pattern has been matched and before the
  200.  * corresponding action - sets up yytext
  201.  */
  202. #define YY_DO_BEFORE_ACTION \
  203.     yytext = yy_bp; \
  204.     yyleng = yy_cp - yy_bp; \
  205.     yy_hold_char = *yy_cp; \
  206.     *yy_cp = '\0'; \
  207.     yy_c_buf_p = yy_cp;
  208.  
  209. #define EOB_ACT_CONTINUE_SCAN 0
  210. #define EOB_ACT_END_OF_FILE 1
  211. #define EOB_ACT_LAST_MATCH 2
  212.  
  213. /* return all but the first 'n' matched characters back to the input stream */
  214. #define yyless(n) \
  215.     do \
  216.         { \
  217.         /* undo effects of setting up yytext */ \
  218.         *yy_cp = yy_hold_char; \
  219.         yy_c_buf_p = yy_cp = yy_bp + n; \
  220.         YY_DO_BEFORE_ACTION; /* set up yytext again */ \
  221.         } \
  222.     while ( 0 )
  223.  
  224. #define unput(c) yyunput( c, yytext )
  225.  
  226.  
  227. struct yy_buffer_state
  228.     {
  229.     FILE *yy_input_file;
  230.  
  231.     YY_CHAR *yy_ch_buf;        /* input buffer */
  232.     YY_CHAR *yy_buf_pos;    /* current position in input buffer */
  233.  
  234.     /* size of input buffer in bytes, not including room for EOB characters*/
  235.     int yy_buf_size;    
  236.  
  237.     /* number of characters read into yy_ch_buf, not including EOB characters */
  238.     int yy_n_chars;
  239.  
  240.     int yy_eof_status;        /* whether we've seen an EOF on this buffer */
  241. #define EOF_NOT_SEEN 0
  242.     /* "pending" happens when the EOF has been seen but there's still
  243.      * some text process
  244.      */
  245. #define EOF_PENDING 1
  246. #define EOF_DONE 2
  247.     };
  248.  
  249. static YY_BUFFER_STATE yy_current_buffer;
  250.  
  251. /* we provide macros for accessing buffer states in case in the
  252.  * future we want to put the buffer states in a more general
  253.  * "scanner state"
  254.  */
  255. #define YY_CURRENT_BUFFER yy_current_buffer
  256.  
  257.  
  258. /* yy_hold_char holds the character lost when yytext is formed */
  259. static YY_CHAR yy_hold_char;
  260.  
  261. static int yy_n_chars;        /* number of characters read into yy_ch_buf */
  262.  
  263.  
  264.  
  265. #ifndef YY_USER_ACTION
  266. #define YY_USER_ACTION
  267. #endif
  268.  
  269. #ifndef YY_USER_INIT
  270. #define YY_USER_INIT
  271. #endif
  272.  
  273. extern YY_CHAR *yytext;
  274. extern int yyleng;
  275. extern FILE *yyin, *yyout;
  276.  
  277. YY_CHAR *yytext;
  278. int yyleng;
  279.  
  280. FILE *yyin = stdin, *yyout = stdout;
  281.  
  282. #define YY_END_OF_BUFFER 18
  283. typedef int yy_state_type;
  284. static const short int yy_accept[64] =
  285.     {   0,
  286.         0,    0,    0,    0,    0,    0,   18,   16,   15,   16,
  287.        16,   16,   16,   16,    5,   16,    3,   16,   16,    8,
  288.        16,    0,   13,    0,    0,    0,   12,    7,    0,    0,
  289.         5,    0,    0,    0,    0,    0,    0,    0,    0,    9,
  290.         0,   13,    0,   14,    0,    0,   11,    0,    0,   10,
  291.         0,    0,    4,    0,    0,    0,    0,    0,    6,    1,
  292.         0,    2,    0
  293.     } ;
  294.  
  295. static const YY_CHAR yy_ec[128] =
  296.     {   0,
  297.         1,    1,    1,    1,    1,    1,    1,    1,    2,    3,
  298.         2,    1,    1,    1,    1,    1,    1,    1,    1,    1,
  299.         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
  300.         1,    2,    1,    4,    5,    1,    1,    1,    6,    1,
  301.         1,    7,    1,    1,    1,    1,    8,    9,    1,    1,
  302.         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
  303.         1,    1,    1,    1,    1,    1,    1,    1,    1,   10,
  304.         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
  305.         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
  306.         1,   11,    1,    1,    1,    1,    1,    1,    1,   12,
  307.  
  308.        13,   14,    1,    1,   15,    1,    1,   16,    1,   17,
  309.         1,    1,    1,    1,   18,    1,    1,    1,    1,   10,
  310.         1,    1,    1,    1,    1,    1,    1
  311.     } ;
  312.  
  313. static const YY_CHAR yy_meta[19] =
  314.     {   0,
  315.         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
  316.         1,    1,    1,    1,    1,    1,    1,    1
  317.     } ;
  318.  
  319. static const short int yy_base[71] =
  320.     {   0,
  321.         0,    7,   13,   18,   22,    0,   93,   94,   94,   23,
  322.        81,   83,   23,    0,   30,   28,   94,   35,   44,   94,
  323.        82,   37,   94,   57,   83,   29,   94,   94,   85,   42,
  324.        40,   41,   73,   83,   47,    0,    0,   34,   71,   94,
  325.        54,   58,   67,   94,   78,   80,   94,   64,   79,   94,
  326.        63,   68,   94,   65,   76,   64,   61,   72,   94,   94,
  327.        58,   94,   94,   63,   62,   53,   52,   32,   17,    0
  328.     } ;
  329.  
  330. static const short int yy_def[71] =
  331.     {   0,
  332.        64,   64,   64,   64,   64,    5,   63,   63,   63,   65,
  333.        66,   63,   63,   63,   63,   63,   63,   63,   63,   63,
  334.        63,   65,   63,   67,   63,   63,   63,   63,   68,   63,
  335.        63,   63,   63,   69,   63,   19,   19,   63,   63,   63,
  336.        65,   65,   67,   63,   63,   68,   63,   63,   69,   63,
  337.        63,   63,   63,   63,   70,   63,   63,   70,   63,   63,
  338.        63,   63,    0,   63,   63,   63,   63,   63,   63,   63
  339.     } ;
  340.  
  341. static const short int yy_nxt[113] =
  342.     {   0,
  343.        58,   30,    9,   10,   31,   11,   12,   13,   14,    9,
  344.        10,   15,   11,   12,   16,   17,   10,   49,   11,   18,
  345.        17,   10,   19,   11,   20,   10,   23,   11,   21,   28,
  346.        29,   32,   46,   24,   28,   34,   35,   45,   45,   36,
  347.        23,   32,   32,   30,   33,   37,   31,   24,   35,   51,
  348.        52,   36,   41,   25,   33,   33,   38,   23,   39,   22,
  349.        42,   23,   22,    8,   24,   54,   54,   43,   24,   22,
  350.        42,   62,   55,   55,   59,   61,   60,   43,   59,   57,
  351.        56,   50,   47,   44,   53,   50,   48,   47,   44,   40,
  352.        27,   26,   63,    7,   63,   63,   63,   63,   63,   63,
  353.  
  354.        63,   63,   63,   63,   63,   63,   63,   63,   63,   63,
  355.        63,   63
  356.     } ;
  357.  
  358. static const short int yy_chk[113] =
  359.     {   0,
  360.        70,   14,    1,    1,   14,    1,    1,    1,    2,    2,
  361.         2,    2,    2,    2,    2,    3,    3,   69,    3,    4,
  362.         4,    4,    4,    4,    5,    5,   10,    5,    5,   13,
  363.        13,   15,   68,   10,   16,   16,   18,   26,   26,   18,
  364.        22,   31,   32,   30,   15,   19,   30,   22,   35,   38,
  365.        38,   35,   67,   66,   31,   32,   19,   41,   19,   24,
  366.        24,   42,   65,   64,   41,   48,   54,   24,   42,   43,
  367.        43,   61,   48,   54,   58,   57,   56,   43,   55,   52,
  368.        51,   49,   46,   45,   39,   34,   33,   29,   25,   21,
  369.        12,   11,    7,   63,   63,   63,   63,   63,   63,   63,
  370.  
  371.        63,   63,   63,   63,   63,   63,   63,   63,   63,   63,
  372.        63,   63
  373.     } ;
  374.  
  375. static yy_state_type yy_last_accepting_state;
  376. static YY_CHAR *yy_last_accepting_cpos;
  377.  
  378. /* the intent behind this definition is that it'll catch
  379.  * any uses of REJECT which flex missed
  380.  */
  381. #define REJECT reject_used_but_not_detected
  382. #define yymore() yymore_used_but_not_detected
  383. #define YY_MORE_ADJ 0
  384.  
  385. /* these variables are all declared out here so that section 3 code can
  386.  * manipulate them
  387.  */
  388. /* points to current character in buffer */
  389. static YY_CHAR *yy_c_buf_p = (YY_CHAR *) 0;
  390. static int yy_init = 1;        /* whether we need to initialize */
  391. static int yy_start = 0;    /* start state number */
  392.  
  393. /* flag which is used to allow yywrap()'s to do buffer switches
  394.  * instead of setting up a fresh yyin.  A bit of a hack ...
  395.  */
  396. static int yy_did_buffer_switch_on_eof;
  397.  
  398. static yy_state_type yy_get_previous_state YY_PROTO(( void ));
  399. static yy_state_type yy_try_NUL_trans YY_PROTO(( yy_state_type current_state ));
  400. static int yy_get_next_buffer YY_PROTO(( void ));
  401. static void yyunput YY_PROTO(( YY_CHAR c, YY_CHAR *buf_ptr ));
  402. void yyrestart YY_PROTO(( FILE *input_file ));
  403. void yy_switch_to_buffer YY_PROTO(( YY_BUFFER_STATE new_buffer ));
  404. void yy_load_buffer_state YY_PROTO(( void ));
  405. YY_BUFFER_STATE yy_create_buffer YY_PROTO(( FILE *file, int size ));
  406. void yy_delete_buffer YY_PROTO(( YY_BUFFER_STATE b ));
  407. void yy_init_buffer YY_PROTO(( YY_BUFFER_STATE b, FILE *file ));
  408. void strip_high_bits YY_PROTO(( YY_CHAR *buf,size_t len));
  409. #define yy_new_buffer yy_create_buffer
  410.  
  411. #ifdef __cplusplus
  412. static int yyinput YY_PROTO(( void ));
  413. #else
  414. static int input YY_PROTO(( void ));
  415. #endif
  416.  
  417. YY_DECL
  418.     {
  419.     register yy_state_type yy_current_state;
  420.     register YY_CHAR *yy_cp, *yy_bp;
  421.     register int yy_act;
  422.  
  423.  
  424.  
  425.  
  426.     if ( yy_init )
  427.     {
  428.     YY_USER_INIT;
  429.  
  430.     if ( ! yy_start )
  431.         yy_start = 1;    /* first start state */
  432.  
  433.     if ( ! yyin )
  434.         yyin = stdin;
  435.  
  436.     if ( ! yyout )
  437.         yyout = stdout;
  438.  
  439.     if ( yy_current_buffer )
  440.         yy_init_buffer( yy_current_buffer, yyin );
  441.     else
  442.         yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE );
  443.  
  444.     yy_load_buffer_state();
  445.  
  446.     yy_init = 0;
  447.     }
  448.  
  449.     while ( 1 )        /* loops until end-of-file is reached */
  450.     {
  451.     yy_cp = yy_c_buf_p;
  452.  
  453.     /* support of yytext */
  454.     *yy_cp = yy_hold_char;
  455.  
  456.     /* yy_bp points to the position in yy_ch_buf of the start of the
  457.      * current run.
  458.      */
  459.     yy_bp = yy_cp;
  460.  
  461.     yy_current_state = yy_start;
  462.     if ( yy_bp[-1] == '\n' )
  463.         ++yy_current_state;
  464. yy_match:
  465.     do
  466.         {
  467.         register YY_CHAR yy_c = yy_ec[*yy_cp];
  468.         if ( yy_accept[yy_current_state] )
  469.         {
  470.         yy_last_accepting_state = yy_current_state;
  471.         yy_last_accepting_cpos = yy_cp;
  472.         }
  473.         while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
  474.         {
  475.         yy_current_state = yy_def[yy_current_state];
  476.         if ( yy_current_state >= 64 )
  477.             yy_c = yy_meta[yy_c];
  478.         }
  479.         yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
  480.         ++yy_cp;
  481.         }
  482.     while ( yy_current_state != 63 );
  483.     yy_cp = yy_last_accepting_cpos;
  484.     yy_current_state = yy_last_accepting_state;
  485.  
  486. yy_find_action:
  487.     yy_act = yy_accept[yy_current_state];
  488.  
  489.     YY_DO_BEFORE_ACTION;
  490.     YY_USER_ACTION;
  491.  
  492. do_action:    /* this label is used only to access EOF actions */
  493.  
  494.  
  495.     switch ( yy_act )
  496.         {
  497.         case 0: /* must backtrack */
  498.         /* undo the effects of YY_DO_BEFORE_ACTION */
  499.         *yy_cp = yy_hold_char;
  500.         yy_cp = yy_last_accepting_cpos;
  501.         yy_current_state = yy_last_accepting_state;
  502.         goto yy_find_action;
  503.  
  504. case 1:
  505. # line 32 "c_lines.l"
  506. {
  507.                         if (--nested == 0)
  508.                             BEGIN INITIAL;
  509.                       }
  510.     YY_BREAK
  511. case 2:
  512. # line 37 "c_lines.l"
  513. {
  514.                         ppd++;
  515.                         if (--nested==0)
  516.                             BEGIN INITIAL;
  517.                 }
  518.     YY_BREAK
  519. case 3:
  520. # line 43 "c_lines.l"
  521. {       skipped++;  }
  522.     YY_BREAK
  523. case 4:
  524. # line 45 "c_lines.l"
  525. {       nested++;   }
  526.     YY_BREAK
  527. case 5:
  528. # line 47 "c_lines.l"
  529. {
  530.                     ppd++;
  531.                 }
  532.     YY_BREAK
  533. case 6:
  534. *yy_cp = yy_hold_char; /* undo effects of setting up yytext */
  535. yy_c_buf_p = yy_cp -= 1;
  536. YY_DO_BEFORE_ACTION; /* set up yytext again */
  537. # line 51 "c_lines.l"
  538. {
  539.                         ppd++;
  540.                         nested++;
  541.                         BEGIN SKIP;
  542.                 }
  543.     YY_BREAK
  544. case 7:
  545. # line 57 "c_lines.l"
  546. {
  547.                     comments++;
  548.                     BEGIN COMMENT;
  549.                 }
  550.     YY_BREAK
  551. case 8:
  552. # line 62 "c_lines.l"
  553. {
  554.                     comment_lines++;
  555.                 }
  556.     YY_BREAK
  557. case 9:
  558. # line 66 "c_lines.l"
  559. {
  560.                     BEGIN INITIAL;
  561.                 }
  562.     YY_BREAK
  563. case 10:
  564. *yy_cp = yy_hold_char; /* undo effects of setting up yytext */
  565. yy_c_buf_p = yy_cp -= 1;
  566. YY_DO_BEFORE_ACTION; /* set up yytext again */
  567. # line 70 "c_lines.l"
  568. {
  569.                     fl_cpp++;
  570.                     comments++;
  571.                     comment_lines++;
  572.                 }
  573.     YY_BREAK
  574. case 11:
  575. *yy_cp = yy_hold_char; /* undo effects of setting up yytext */
  576. yy_c_buf_p = yy_cp -= 1;
  577. YY_DO_BEFORE_ACTION; /* set up yytext again */
  578. # line 76 "c_lines.l"
  579. {
  580.                     comments++;
  581.                 }
  582.     YY_BREAK
  583. case 12:
  584. # line 80 "c_lines.l"
  585. {
  586.                     printf("found unmatched close-comment");
  587.                 }
  588.     YY_BREAK
  589. case 13:
  590. # line 84 "c_lines.l"
  591. ;   /* This recognizes and ignores string constants */
  592.     YY_BREAK
  593. case 14:
  594. # line 85 "c_lines.l"
  595. ;   /* This does the same for character constants   */
  596.     YY_BREAK
  597. case 15:
  598. # line 86 "c_lines.l"
  599. nl++;
  600.     YY_BREAK
  601. case 16:
  602. # line 88 "c_lines.l"
  603. ;
  604.     YY_BREAK
  605. case 17:
  606. # line 90 "c_lines.l"
  607. ECHO;
  608.     YY_BREAK
  609. case YY_STATE_EOF(INITIAL):
  610. case YY_STATE_EOF(SKIP):
  611. case YY_STATE_EOF(COMMENT):
  612.     yyterminate();
  613.  
  614.         case YY_END_OF_BUFFER:
  615.         {
  616.         /* amount of text matched not including the EOB char */
  617.         int yy_amount_of_matched_text = yy_cp - yytext - 1;
  618.  
  619.         /* undo the effects of YY_DO_BEFORE_ACTION */
  620.         *yy_cp = yy_hold_char;
  621.  
  622.         /* note that here we test for yy_c_buf_p "<=" to the position
  623.          * of the first EOB in the buffer, since yy_c_buf_p will
  624.          * already have been incremented past the NUL character
  625.          * (since all states make transitions on EOB to the end-
  626.          * of-buffer state).  Contrast this with the test in yyinput().
  627.          */
  628.         if ( yy_c_buf_p <= &yy_current_buffer->yy_ch_buf[yy_n_chars] )
  629.             /* this was really a NUL */
  630.             {
  631.             yy_state_type yy_next_state;
  632.  
  633.             yy_c_buf_p = yytext + yy_amount_of_matched_text;
  634.  
  635.             yy_current_state = yy_get_previous_state();
  636.  
  637.             /* okay, we're now positioned to make the
  638.              * NUL transition.  We couldn't have
  639.              * yy_get_previous_state() go ahead and do it
  640.              * for us because it doesn't know how to deal
  641.              * with the possibility of jamming (and we
  642.              * don't want to build jamming into it because
  643.              * then it will run more slowly)
  644.              */
  645.  
  646.             yy_next_state = yy_try_NUL_trans( yy_current_state );
  647.  
  648.             yy_bp = yytext + YY_MORE_ADJ;
  649.  
  650.             if ( yy_next_state )
  651.             {
  652.             /* consume the NUL */
  653.             yy_cp = ++yy_c_buf_p;
  654.             yy_current_state = yy_next_state;
  655.             goto yy_match;
  656.             }
  657.  
  658.             else
  659.             {
  660.                 yy_cp = yy_last_accepting_cpos;
  661.                 yy_current_state = yy_last_accepting_state;
  662.             goto yy_find_action;
  663.             }
  664.             }
  665.  
  666.         else switch ( yy_get_next_buffer() )
  667.             {
  668.             case EOB_ACT_END_OF_FILE:
  669.             {
  670.             yy_did_buffer_switch_on_eof = 0;
  671.  
  672.             if ( yywrap() )
  673.                 {
  674.                 /* note: because we've taken care in
  675.                  * yy_get_next_buffer() to have set up yytext,
  676.                  * we can now set up yy_c_buf_p so that if some
  677.                  * total hoser (like flex itself) wants
  678.                  * to call the scanner after we return the
  679.                  * YY_NULL, it'll still work - another YY_NULL
  680.                  * will get returned.
  681.                  */
  682.                 yy_c_buf_p = yytext + YY_MORE_ADJ;
  683.  
  684.                 yy_act = YY_STATE_EOF((yy_start - 1) / 2);
  685.                 goto do_action;
  686.                 }
  687.  
  688.             else
  689.                 {
  690.                 if ( ! yy_did_buffer_switch_on_eof )
  691.                 YY_NEW_FILE;
  692.                 }
  693.             }
  694.             break;
  695.  
  696.             case EOB_ACT_CONTINUE_SCAN:
  697.             yy_c_buf_p = yytext + yy_amount_of_matched_text;
  698.  
  699.             yy_current_state = yy_get_previous_state();
  700.  
  701.             yy_cp = yy_c_buf_p;
  702.             yy_bp = yytext + YY_MORE_ADJ;
  703.             goto yy_match;
  704.  
  705.             case EOB_ACT_LAST_MATCH:
  706.             yy_c_buf_p =
  707.                 &yy_current_buffer->yy_ch_buf[yy_n_chars];
  708.  
  709.             yy_current_state = yy_get_previous_state();
  710.  
  711.             yy_cp = yy_c_buf_p;
  712.             yy_bp = yytext + YY_MORE_ADJ;
  713.             goto yy_find_action;
  714.             }
  715.         break;
  716.         }
  717.  
  718.         default:
  719. #ifdef FLEX_DEBUG
  720.         printf( "action # %d\n", yy_act );
  721. #endif
  722.         YY_FATAL_ERROR(
  723.             "fatal flex scanner internal error--no action found" );
  724.         }
  725.     }
  726.     }
  727.  
  728. /*
  729.     yy_strip_high_bits(char *buf, size_t length )
  730.     Turn any character in 'buf' with it's high bit set into a space.
  731.     Processes 'length' characters.
  732.     Added Jan 1992, by Jerry Coffin.
  733. */
  734.  
  735. yy_strip_high_bits(YY_CHAR *buf,size_t length) {
  736.  
  737.     size_t i=length;
  738.  
  739.     for (;i;i--)
  740.         if (buf[i] & 0x80 )
  741.             buf[i]=' ';
  742. }
  743.  
  744.  
  745. /* yy_get_next_buffer - try to read in a new buffer
  746.  *
  747.  * synopsis
  748.  *     int yy_get_next_buffer();
  749.  *     
  750.  * returns a code representing an action
  751.  *     EOB_ACT_LAST_MATCH - 
  752.  *     EOB_ACT_CONTINUE_SCAN - continue scanning from current position
  753.  *     EOB_ACT_END_OF_FILE - end of file
  754.  */
  755.  
  756. static int yy_get_next_buffer()
  757.  
  758.     {
  759.     register YY_CHAR *dest = yy_current_buffer->yy_ch_buf;
  760.     register YY_CHAR *source = yytext - 1; /* copy prev. char, too */
  761.     register int number_to_move, i;
  762.     int ret_val;
  763.  
  764.     if ( yy_c_buf_p > &yy_current_buffer->yy_ch_buf[yy_n_chars + 1] )
  765.     YY_FATAL_ERROR(
  766.         "fatal flex scanner internal error--end of buffer missed" );
  767.  
  768.     /* try to read more data */
  769.  
  770.     /* first move last chars to start of buffer */
  771.     number_to_move = yy_c_buf_p - yytext;
  772.  
  773.     for ( i = 0; i < number_to_move; ++i )
  774.     *(dest++) = *(source++);
  775.  
  776.     if ( yy_current_buffer->yy_eof_status != EOF_NOT_SEEN )
  777.     /* don't do the read, it's not guaranteed to return an EOF,
  778.      * just force an EOF
  779.      */
  780.     yy_n_chars = 0;
  781.  
  782.     else
  783.     {
  784.     int num_to_read = yy_current_buffer->yy_buf_size - number_to_move - 1;
  785.  
  786.     if ( num_to_read > YY_READ_BUF_SIZE )
  787.         num_to_read = YY_READ_BUF_SIZE;
  788.  
  789.     else if ( num_to_read <= 0 )
  790.         YY_FATAL_ERROR( "fatal error - scanner input buffer overflow" );
  791.  
  792.     /* read in more data */
  793.     YY_INPUT( (&yy_current_buffer->yy_ch_buf[number_to_move]),
  794.           yy_n_chars, num_to_read );
  795.     }
  796.  
  797.     if ( yy_n_chars == 0 )
  798.     {
  799.     if ( number_to_move == 1 )
  800.         {
  801.         ret_val = EOB_ACT_END_OF_FILE;
  802.         yy_current_buffer->yy_eof_status = EOF_DONE;
  803.         }
  804.  
  805.     else
  806.         {
  807.         ret_val = EOB_ACT_LAST_MATCH;
  808.         yy_current_buffer->yy_eof_status = EOF_PENDING;
  809.         }
  810.     }
  811.  
  812.     else
  813.     ret_val = EOB_ACT_CONTINUE_SCAN;
  814.  
  815.     yy_n_chars += number_to_move;
  816.     yy_current_buffer->yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR;
  817.     yy_current_buffer->yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
  818.  
  819.     /* yytext begins at the second character in yy_ch_buf; the first
  820.      * character is the one which preceded it before reading in the latest
  821.      * buffer; it needs to be kept around in case it's a newline, so
  822.      * yy_get_previous_state() will have with '^' rules active
  823.      */
  824.  
  825.     yytext = &yy_current_buffer->yy_ch_buf[1];
  826.  
  827.     return ( ret_val );
  828.     }
  829.  
  830.  
  831. /* yy_get_previous_state - get the state just before the EOB char was reached
  832.  *
  833.  * synopsis
  834.  *     yy_state_type yy_get_previous_state();
  835.  */
  836.  
  837. static yy_state_type yy_get_previous_state()
  838.  
  839.     {
  840.     register yy_state_type yy_current_state;
  841.     register YY_CHAR *yy_cp;
  842.  
  843.     register YY_CHAR *yy_bp = yytext;
  844.  
  845.     yy_current_state = yy_start;
  846.     if ( yy_bp[-1] == '\n' )
  847.     ++yy_current_state;
  848.  
  849.     for ( yy_cp = yytext + YY_MORE_ADJ; yy_cp < yy_c_buf_p; ++yy_cp )
  850.     {
  851.     register YY_CHAR yy_c = (*yy_cp ? yy_ec[*yy_cp] : 1);
  852.     if ( yy_accept[yy_current_state] )
  853.         {
  854.         yy_last_accepting_state = yy_current_state;
  855.         yy_last_accepting_cpos = yy_cp;
  856.         }
  857.     while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
  858.         {
  859.         yy_current_state = yy_def[yy_current_state];
  860.         if ( yy_current_state >= 64 )
  861.         yy_c = yy_meta[yy_c];
  862.         }
  863.     yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
  864.     }
  865.  
  866.     return ( yy_current_state );
  867.     }
  868.  
  869.  
  870. /* yy_try_NUL_trans - try to make a transition on the NUL character
  871.  *
  872.  * synopsis
  873.  *     next_state = yy_try_NUL_trans( current_state );
  874.  */
  875.  
  876. #ifdef YY_USE_PROTOS
  877. static yy_state_type yy_try_NUL_trans( register yy_state_type yy_current_state )
  878. #else
  879. static yy_state_type yy_try_NUL_trans( yy_current_state )
  880. register yy_state_type yy_current_state;
  881. #endif
  882.  
  883.     {
  884.     register int yy_is_jam;
  885.     register YY_CHAR *yy_cp = yy_c_buf_p;
  886.  
  887.     register YY_CHAR yy_c = 1;
  888.     if ( yy_accept[yy_current_state] )
  889.     {
  890.     yy_last_accepting_state = yy_current_state;
  891.     yy_last_accepting_cpos = yy_cp;
  892.     }
  893.     while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
  894.     {
  895.     yy_current_state = yy_def[yy_current_state];
  896.     if ( yy_current_state >= 64 )
  897.         yy_c = yy_meta[yy_c];
  898.     }
  899.     yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
  900.     yy_is_jam = (yy_current_state == 63);
  901.  
  902.     return ( yy_is_jam ? 0 : yy_current_state );
  903.     }
  904.  
  905.  
  906. #ifdef YY_USE_PROTOS
  907. static void yyunput( YY_CHAR c, register YY_CHAR *yy_bp )
  908. #else
  909. static void yyunput( c, yy_bp )
  910. YY_CHAR c;
  911. register YY_CHAR *yy_bp;
  912. #endif
  913.  
  914.     {
  915.     register YY_CHAR *yy_cp = yy_c_buf_p;
  916.  
  917.     /* undo effects of setting up yytext */
  918.     *yy_cp = yy_hold_char;
  919.  
  920.     if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 )
  921.     { /* need to shift things up to make room */
  922.     register int number_to_move = yy_n_chars + 2; /* +2 for EOB chars */
  923.     register YY_CHAR *dest =
  924.         &yy_current_buffer->yy_ch_buf[yy_current_buffer->yy_buf_size + 2];
  925.     register YY_CHAR *source =
  926.         &yy_current_buffer->yy_ch_buf[number_to_move];
  927.  
  928.     while ( source > yy_current_buffer->yy_ch_buf )
  929.         *--dest = *--source;
  930.  
  931.     yy_cp += dest - source;
  932.     yy_bp += dest - source;
  933.     yy_n_chars = yy_current_buffer->yy_buf_size;
  934.  
  935.     if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 )
  936.         YY_FATAL_ERROR( "flex scanner push-back overflow" );
  937.     }
  938.  
  939.     if ( yy_cp > yy_bp && yy_cp[-1] == '\n' )
  940.     yy_cp[-2] = '\n';
  941.  
  942.     *--yy_cp = c;
  943.  
  944.     /* note: the formal parameter *must* be called "yy_bp" for this
  945.      *       macro to now work correctly
  946.      */
  947.     YY_DO_BEFORE_ACTION; /* set up yytext again */
  948.     }
  949.  
  950.  
  951. #ifdef __cplusplus
  952. static int yyinput()
  953. #else
  954. static int input()
  955. #endif
  956.  
  957.     {
  958.     int c;
  959.     YY_CHAR *yy_cp = yy_c_buf_p;
  960.  
  961.     *yy_cp = yy_hold_char;
  962.  
  963.     if ( *yy_c_buf_p == YY_END_OF_BUFFER_CHAR )
  964.     {
  965.     /* yy_c_buf_p now points to the character we want to return.
  966.      * If this occurs *before* the EOB characters, then it's a
  967.      * valid NUL; if not, then we've hit the end of the buffer.
  968.      */
  969.     if ( yy_c_buf_p < &yy_current_buffer->yy_ch_buf[yy_n_chars] )
  970.         /* this was really a NUL */
  971.         *yy_c_buf_p = '\0';
  972.  
  973.     else
  974.         { /* need more input */
  975.         yytext = yy_c_buf_p;
  976.         ++yy_c_buf_p;
  977.  
  978.         switch ( yy_get_next_buffer() )
  979.         {
  980.         case EOB_ACT_END_OF_FILE:
  981.             {
  982.             if ( yywrap() )
  983.             {
  984.             yy_c_buf_p = yytext + YY_MORE_ADJ;
  985.             return ( EOF );
  986.             }
  987.  
  988.             YY_NEW_FILE;
  989.  
  990. #ifdef __cplusplus
  991.             return ( yyinput() );
  992. #else
  993.             return ( input() );
  994. #endif
  995.             }
  996.             break;
  997.  
  998.         case EOB_ACT_CONTINUE_SCAN:
  999.             yy_c_buf_p = yytext + YY_MORE_ADJ;
  1000.             break;
  1001.  
  1002.         case EOB_ACT_LAST_MATCH:
  1003. #ifdef __cplusplus
  1004.             YY_FATAL_ERROR( "unexpected last match in yyinput()" );
  1005. #else
  1006.             YY_FATAL_ERROR( "unexpected last match in input()" );
  1007. #endif
  1008.         }
  1009.         }
  1010.     }
  1011.  
  1012.     c = *yy_c_buf_p;
  1013.     yy_hold_char = *++yy_c_buf_p;
  1014.  
  1015.     return ( c );
  1016.     }
  1017.  
  1018.  
  1019. #ifdef YY_USE_PROTOS
  1020. void yyrestart( FILE *input_file )
  1021. #else
  1022. void yyrestart( input_file )
  1023. FILE *input_file;
  1024. #endif
  1025.  
  1026.     {
  1027.     yy_init_buffer( yy_current_buffer, input_file );
  1028.     yy_load_buffer_state();
  1029.     }
  1030.  
  1031.  
  1032. #ifdef YY_USE_PROTOS
  1033. void yy_switch_to_buffer( YY_BUFFER_STATE new_buffer )
  1034. #else
  1035. void yy_switch_to_buffer( new_buffer )
  1036. YY_BUFFER_STATE new_buffer;
  1037. #endif
  1038.  
  1039.     {
  1040.     if ( yy_current_buffer == new_buffer )
  1041.     return;
  1042.  
  1043.     if ( yy_current_buffer )
  1044.     {
  1045.     /* flush out information for old buffer */
  1046.     *yy_c_buf_p = yy_hold_char;
  1047.     yy_current_buffer->yy_buf_pos = yy_c_buf_p;
  1048.     yy_current_buffer->yy_n_chars = yy_n_chars;
  1049.     }
  1050.  
  1051.     yy_current_buffer = new_buffer;
  1052.     yy_load_buffer_state();
  1053.  
  1054.     /* we don't actually know whether we did this switch during
  1055.      * EOF (yywrap()) processing, but the only time this flag
  1056.      * is looked at is after yywrap() is called, so it's safe
  1057.      * to go ahead and always set it.
  1058.      */
  1059.     yy_did_buffer_switch_on_eof = 1;
  1060.     }
  1061.  
  1062.  
  1063. #ifdef YY_USE_PROTOS
  1064. void yy_load_buffer_state( void )
  1065. #else
  1066. void yy_load_buffer_state()
  1067. #endif
  1068.  
  1069.     {
  1070.     yy_n_chars = yy_current_buffer->yy_n_chars;
  1071.     yytext = yy_c_buf_p = yy_current_buffer->yy_buf_pos;
  1072.     yyin = yy_current_buffer->yy_input_file;
  1073.     yy_hold_char = *yy_c_buf_p;
  1074.     }
  1075.  
  1076.  
  1077. #ifdef YY_USE_PROTOS
  1078. YY_BUFFER_STATE yy_create_buffer( FILE *file, int size )
  1079. #else
  1080. YY_BUFFER_STATE yy_create_buffer( file, size )
  1081. FILE *file;
  1082. int size;
  1083. #endif
  1084.  
  1085.     {
  1086.     YY_BUFFER_STATE b;
  1087.  
  1088.     b = (YY_BUFFER_STATE) malloc( sizeof( struct yy_buffer_state ) );
  1089.  
  1090.     if ( ! b )
  1091.     YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
  1092.  
  1093.     b->yy_buf_size = size;
  1094.  
  1095.     /* yy_ch_buf has to be 2 characters longer than the size given because
  1096.      * we need to put in 2 end-of-buffer characters.
  1097.      */
  1098.     b->yy_ch_buf = (YY_CHAR *) malloc( (unsigned) (b->yy_buf_size + 2) );
  1099.  
  1100.     if ( ! b->yy_ch_buf )
  1101.     YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
  1102.  
  1103.     yy_init_buffer( b, file );
  1104.  
  1105.     return ( b );
  1106.     }
  1107.  
  1108.  
  1109. #ifdef YY_USE_PROTOS
  1110. void yy_delete_buffer( YY_BUFFER_STATE b )
  1111. #else
  1112. void yy_delete_buffer( b )
  1113. YY_BUFFER_STATE b;
  1114. #endif
  1115.  
  1116.     {
  1117.     if ( b == yy_current_buffer )
  1118.     yy_current_buffer = (YY_BUFFER_STATE) 0;
  1119.  
  1120.     free( (char *) b->yy_ch_buf );
  1121.     free( (char *) b );
  1122.     }
  1123.  
  1124.  
  1125. #ifdef YY_USE_PROTOS
  1126. void yy_init_buffer( YY_BUFFER_STATE b, FILE *file )
  1127. #else
  1128. void yy_init_buffer( b, file )
  1129. YY_BUFFER_STATE b;
  1130. FILE *file;
  1131. #endif
  1132.  
  1133.     {
  1134.     b->yy_input_file = file;
  1135.  
  1136.     /* we put in the '\n' and start reading from [1] so that an
  1137.      * initial match-at-newline will be true.
  1138.      */
  1139.  
  1140.     b->yy_ch_buf[0] = '\n';
  1141.     b->yy_n_chars = 1;
  1142.  
  1143.     /* we always need two end-of-buffer characters.  The first causes
  1144.      * a transition to the end-of-buffer state.  The second causes
  1145.      * a jam in that state.
  1146.      */
  1147.     b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
  1148.     b->yy_ch_buf[2] = YY_END_OF_BUFFER_CHAR;
  1149.  
  1150.     b->yy_buf_pos = &b->yy_ch_buf[1];
  1151.  
  1152.     b->yy_eof_status = EOF_NOT_SEEN;
  1153.     }
  1154. # line 90 "c_lines.l"
  1155.  
  1156.  
  1157. int main(int argc,char **argv) {
  1158.  
  1159. #ifdef __TURBOC__
  1160. #include <stdlib.h>
  1161. #define _MAX_PATH MAXPATH
  1162. #endif
  1163.  
  1164.     unsigned tppd=0,tnl=0,tl=0;
  1165.     unsigned total_comments=0,total_comment_lines=0;
  1166.     unsigned total_skipped=0;
  1167.     char file_name[_MAX_PATH];
  1168.     char **extension;
  1169.     char *end;
  1170.  
  1171.     if (argc<2) {
  1172.         /* read standard input if no file name supplied */
  1173.         yylex();
  1174.         nl-=ppd+fl_cpp;
  1175.         tppd+=ppd;
  1176.         tnl+=nl;
  1177.         total_comments+=comments;
  1178.         total_comment_lines+=comment_lines;
  1179.         total_skipped+=skipped;
  1180.         tl+=fl_cpp+ppd+nl+comment_lines+skipped;
  1181.         files=2;
  1182.     }
  1183.  
  1184.     else while (--argc) {
  1185.  
  1186.         nl=ppd=fl_cpp=comments=comment_lines=skipped=0;
  1187.  
  1188.         /* otherwise, open each file supplied in turn. */
  1189.         strcpy(file_name,*++argv);
  1190.         end=strchr(file_name,'\0');
  1191.         if ((yyin=fopen(file_name,"r"))==NULL && strchr(*argv,'.')==NULL) {
  1192.             for (extension=extensions;**extension;extension++) {
  1193.                 strcpy(end,*extension);
  1194.                 if ((yyin=fopen(file_name,"r"))!=NULL)
  1195.                     break;
  1196.             }
  1197.         }
  1198.         if (yyin==NULL) {
  1199.             printf("\n\nError: Unable to open %s\n",*argv);
  1200.             continue;
  1201.         }
  1202.         files++;
  1203.         yylex();        /* do dirty work on file itself */
  1204.         /* subtract preprocessor lines and full-line    */
  1205.         /* c++ comments to get number of code lines.    */
  1206.         /* new-lines contained in normal comments are   */
  1207.         /* dealt with in the rule for comments          */
  1208.         nl-=ppd+fl_cpp;
  1209.         /* report what we found                         */
  1210.         printf("\n\t\"%s\" contains:"
  1211.             "\n%u preprocessor directives, %u comments on %u lines,"
  1212.             "\n%u lines skipped due to pre-processor directives"
  1213.             "\nand %u lines of code, for a total of %u lines",
  1214.             file_name,ppd,comments,comment_lines,skipped,nl,
  1215.             ppd+nl+comment_lines+skipped);
  1216.         /* current file's stats to totals               */
  1217.         tppd+=ppd;
  1218.         tnl+=nl;
  1219.         total_comments+=comments;
  1220.         total_comment_lines+=comment_lines;
  1221.         total_skipped+=skipped;
  1222.         tl+=fl_cpp+ppd+nl+comment_lines+skipped;
  1223.         /* reset yylex() so we can do another file.  If     */
  1224.         /* this isn't done, it won't read other files       */
  1225.         /* after it has reached te end of the first one.    */
  1226.         /* This particular call is specific to  Flex.       */
  1227.         /* lex, LeX, etc. use other  mechanisms.  LeX       */
  1228.         /* requires that you open files with ii_newfile()   */
  1229.         /* I'm not sure how reall AT&T lex deals with this. */
  1230.         yyrestart(yyin);
  1231.         fclose(yyin);
  1232.     }
  1233.     /* print final totals                               */
  1234.     if (files>1)
  1235.         printf("\n\tTotals:"
  1236.             "\n%u preprocessor directives, %u comments on %u lines,"
  1237.             "\n%u lines skipped due to pre-processor directives"
  1238.             "\nand %u lines of code, for a grand total of %u lines"
  1239.             "\nmodules average %d lines",
  1240.             tppd,total_comments,total_comment_lines,total_skipped,tnl,tl,tl/files);
  1241.         /* and we're outta here !                           */
  1242.     return 0;
  1243. }
  1244.